package com.yycwxt.modules.admin.core_flows;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yycwxt.domain.Flows;
import com.yycwxt.domain.Shop;
import com.yycwxt.domain.Store;
import com.yycwxt.domain.Subject;
import com.yycwxt.modules.admin.bcf.BcfSelectProvider;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * Created by Mr.Zhang on 2022/8/26 21:25
 */

@Mapper
public interface FlowsMapper extends BaseMapper<Flows>{

    // 查询全部
    @Select("SELECT * FROM core_flows;")
    List<Flows> selectAll();

    // 查询账期
    @Select("SELECT distinct account_date FROM core_flows")
    Object[] selectAccountDte();


    // 按照账期查询全部流水
    @Select("SELECT * FROM core_flows WHERE account_date = #{account_date};")
    List<Flows> selectAllByAccountDate(@Param("account_date") Integer accountDate);

    // 根据输入查询
    @Select("SELECT * FROM core_flows WHERE shop_code like concat('%',#{input},'%') or " +
            "store_code like concat('%',#{input},'%') or subject_code like concat('%',#{input},'%') or " +
            "store_name like concat('%',#{input},'%') or subject_name like concat('%',#{input},'%') or shop_name like concat('%',#{input},'%');"
    )
    List<Flows> selectByInput(@Param("input") String input);



    // 查询全部科目名称
    @Select("SELECT distinct fullname FROM core_subject;")
    List<Subject> selectSubjectName();

    // 查询全部店铺编码和店铺
    @Select("SELECT * FROM glb_shop;")
    List<Shop> selectShopName();

    // 查询全部仓库编码
    @Select("SELECT * FROM glb_store;")
    List<Store> selectStoreName();

    // 新增流水
    @Insert("""
            insert into core_flows(order_number, account_date, shop_code, shop_name, 
            store_code, store_name, subject_code, 
            subject_name, subject_direction, cost, remark)
            values(#{order_number}, #{account_date}
                , #{shop_code}, (select name from glb_shop where code = #{shop_code})
                , #{store_code}, (select name from glb_store where code = #{store_code})
                , #{subject_code}, (select fullname from core_subject where code = #{subject_code})
                , #{subject_direction}, #{cost}, #{remark})
            """)
    int insertFlows(@Param("order_number") String orderNumber, @Param("account_date") Integer accountDate,
                    @Param("shop_code") String shopCode,
                    @Param("store_code") String storeCode,
                    @Param("subject_code") String subjectCode,
                    @Param("subject_direction") Integer subjectDirection, @Param("cost") BigDecimal cost,
                    @Param("remark") String remark);




}
